﻿#include "pathexcutewid.h"
#include <QTimer>
#include "taskProcess/TaskProcess.h"
#include "taskProcess/pathexcutequeue.h"
#include "componentmanager.h"
#include "pathshowwid.h"

PathExcuteWid::PathExcuteWid(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	m_show = new PathShowWId(this);
	ui.horizontalLayout_5->addWidget(m_show);
	auto m_task = dynamic_cast<TaskProcess*>(component->GetComponent(Component::component_taskExcutor));
	if (m_task != nullptr) {
		m_path = m_task->GetPathExcutor();
	}

	if (m_path == nullptr) {
		ui.groupBox_2->hide();
		ui.groupBox_2->hide();
	} else {
		InitPathExcutorInfo();
	}
}

PathExcuteWid::~PathExcuteWid()
{
}

void PathExcuteWid::InitPathExcutorInfo()
{
	ui.label->show();
	auto info = m_path->GetPathBuffInfo();
	if (info.execpath.isEmpty()) {
		ui.groupBox_2->hide();
	} else {
		ui.label->hide();
		ui.groupBox_2->show();
		ui.lineEdit->setText(info.execpipe);
		ui.lineEdit_2->setText(info.execpath);
	}

	if (info.waitpath.isEmpty()) {
		ui.groupBox_3->hide();
	} else {
		ui.groupBox_3->show();
		ui.lineEdit_3->setText(info.waitpipe);
		ui.lineEdit_4->setText(info.waitpath);
	}

	if (!ui.groupBox_2->isHidden()) {
		auto path = m_path->GetExecPathList();
		m_show->ShowPath(info.execpath, path);
	}



	QTimer::singleShot(1000, [&]() {
		InitPathExcutorInfo();
		});
}
